package cn.iocoder.yudao.module.wine.controller.app.suggest;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.wine.controller.app.suggest.vo.AppSuggestRespVO;
import cn.iocoder.yudao.module.wine.controller.app.suggest.vo.AppSuggestSaveReqVO;
import cn.iocoder.yudao.module.wine.service.suggest.SuggestService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "App 用户 - 用户建议")
@RestController
@RequestMapping("/wine/suggest")
@Validated
public class AppSuggestController {

    @Resource
    private SuggestService suggestService;

    @GetMapping("/page")
    @Operation(summary = "获取我的建议列表")
    @PreAuthorize("@ss.hasPermission('wine:suggest:query')")
    public CommonResult<List<AppSuggestRespVO>> getSuggestPage() {
        List<AppSuggestRespVO> list = suggestService.getSuggestList();
        return success(list);
    }

    @PostMapping("/create")
    @Operation(summary = "用户发布建议")
    @PreAuthorize("@ss.hasPermission('wine:suggest:create')")
    public CommonResult<Long> publishSuggest(@Valid @RequestBody AppSuggestSaveReqVO createReqVO) {
        return success(suggestService.publishSuggest(createReqVO));
    }

}
